//
//  ZMyOrderListOrderCancelView.m
//  DistributorAB
//
//  Created by LZY on 2019/10/14.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyOrderListOrderCancelView.h"

@interface ZMyOrderListOrderCancelView ()
@end

@implementation ZMyOrderListOrderCancelView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局方法
- (void)setupViewAction{
    
    self.backgroundColor = kColorWithHex(0xb1b0af);
    
    
    UIView *viewCenter = [UIView new];
    viewCenter.backgroundColor = kColorWithHex(0xffffff);
    viewCenter.layer.cornerRadius = 6.0;
    viewCenter.layer.masksToBounds = YES;
    [self addSubview:viewCenter];
    [viewCenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(kScaleNum(331), kScaleNum(239)));
    }];
    
    UIImageView *ivNotice = [UIImageView new];
    ivNotice.image = imgname(@"alert_notice_icon");
    [viewCenter addSubview:ivNotice];
    [ivNotice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(viewCenter);
        make.top.equalTo(viewCenter.mas_top).offset(34);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    
    UILabel *lblNotice = [UILabel new];
    lblNotice.text = @"确定取消该订单?";
    lblNotice.font = [UIFont systemFontOfSize:16];
    lblNotice.textColor = kColorWithHex(0x333333);
    lblNotice.textAlignment = NSTextAlignmentCenter;
    [viewCenter addSubview:lblNotice];
    [lblNotice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(viewCenter);
        make.top.equalTo(ivNotice.mas_bottom).offset(19);
    }];
    
    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnCancel setImage:imgname(@"order_cancel_cancel_icon") forState:UIControlStateNormal];
    [btnCancel addTarget:self action:@selector(btnCancleClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [viewCenter addSubview:btnCancel];
    [btnCancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(viewCenter.mas_leading).offset(kScaleNum(45));
        make.bottom.equalTo(viewCenter.mas_bottom).offset(-22);
        make.size.mas_equalTo(CGSizeMake(113, 36));
    }];
    
    UIButton *btnOk = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnOk setImage:imgname(@"order_cancel_ok_icon") forState:UIControlStateNormal];
    [btnOk addTarget:self action:@selector(btnOKClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [viewCenter addSubview:btnOk];
    [btnOk mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(viewCenter.mas_trailing).offset(-kScaleNum(45));
        make.bottom.equalTo(viewCenter.mas_bottom).offset(-22);
        make.size.mas_equalTo(CGSizeMake(113, 36));
    }];
    
    
}
- (void)setOrderModel:(BShopPartModel *)orderModel{
    if (orderModel) {
        _orderModel = orderModel;
    }
}

#pragma mark - 交互方法
//显示
- (void)showView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    self.frame = window.bounds;
    [window addSubview:self];
}
//关闭
- (void)dismissView{
    [self removeFromSuperview];
}
//我知道了
- (void)btnCancleClickAction:(UIButton *)sender{
    
    [self dismissView];
    
}
- (void)btnOKClickAction:(UIButton *)sender{

        if (self.orderModel) {
            kWeakSelf;
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setObjectIfNotNil:@"" forKey:@"reason"];
            [dict setObjectIfNotNil:self.orderModel.Id forKey:@"id"];
            
            [NetWorkTool POST:CANCEL_ORDERS param:dict success:^(id dic) {
                ShowToastWithText(@"订单取消成功");
                [weakSelf dismissView];
                weakSelf.orderModel.state = @"2";
                if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(orderCancelSuccess)]) {
                    [weakSelf.delegate orderCancelSuccess];
                }
            } other:^(id dic) {
                ShowToastWithText(dic[@"msg"]);
            } fail:^(NSError *error) {
                
            } needUser:YES];
        }
    
}


@end
